package com.tech.cloudapp.biz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tech.cloudapp.biz.service.IBQuestionInfoService;
import com.tech.cloudapp.db.entity.QuestionInfo;
import com.tech.cloudapp.db.entity.QuestionPaper;
import com.tech.cloudapp.db.service.QuestionInfoService;
import com.tech.cloudapp.dto.PageDTO;
import com.tech.cloudapp.po.QuestionInfoPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Primary
@Service
public class BQuestionInfoServiceImpl implements IBQuestionInfoService {

    @Autowired
    private QuestionInfoService questionInfoServiceImpl;

    @Override
    public List<QuestionInfo> list(QuestionInfo questionInfo) {
        QueryWrapper<QuestionInfo> queryWapper = new QueryWrapper();
        queryWapper.eq("paper_id",questionInfo.getPaperId())
                .eq("classify_id",questionInfo.getClassifyId());
        List<QuestionInfo> list = questionInfoServiceImpl.list(queryWapper);
        if(list == null)
        {
            list = new ArrayList<>();
        }

        return list;
    }

    @Override
    public PageDTO page(QuestionInfoPO questionInfoPO) {
        //获取数据记录总数
        QueryWrapper<QuestionInfo> queryWapper = new QueryWrapper();
        queryWapper.eq("paper_id",questionInfoPO.getPaperId())
                .eq("classify_id",questionInfoPO.getClassifyId());
        PageDTO<QuestionInfo> pageDTO = new PageDTO();
        pageDTO.setCurrent(questionInfoPO.getPage());
        pageDTO.setSize(questionInfoPO.getPageSize());
        PageDTO<QuestionInfo> page = questionInfoServiceImpl.page(pageDTO, queryWapper);
        return page;
    }
}
